﻿
using App.Code;
using App.Entity;
using App.IServices;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AppAit.Areas.SystemManage.Controllers
{
    public class ItemsDataController : ControllerBase
    {
        ISys_ItemsDetailServices _itemsDetail;
        public ItemsDataController(ISys_ItemsDetailServices itemsDetail)
        {
            _itemsDetail = itemsDetail;
        }
        /// <summary>
        /// 绑定列表
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(string itemId, string keyword)
        {
            var data = _itemsDetail.GetList(itemId, keyword);
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetSelectJson(string enCode)
        {
            var data = _itemsDetail.GetItemList(enCode);
            List<object> list = new List<object>();
            foreach (Sys_ItemsDetail item in data)
            {
                list.Add(new { id = item.ItemCode, text = item.ItemName });
            }
            return Content(list.ToJson());
        }
        
        /// <summary>
        /// 绑定表单
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = _itemsDetail.GetForm(keyValue);
            return Content(data.ToJson());
        }

        /// <summary>
        /// 添加/修改
        /// </summary>
        /// <param name="itemsDetailEntity"></param>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(Sys_ItemsDetail itemsDetailEntity, string keyValue)
        {
            _itemsDetail.SubmitForm(itemsDetailEntity, keyValue);
            return Success("操作成功。");
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            _itemsDetail.DeleteForm(keyValue);
            return Success("删除成功。");
        }
    }
}